<template lang="">
  <t-dialog
    :visible="props.visibles"
    width="40%"
    header="新增水质断面检测点成果基本信息详情表表"
    :confirm-loading="submitLoading"
    :destroy-on-close="true"
    @confirm="handleOnConfirm"
    @cancel="handleClose"
    @close="handleClose"
  >
    <t-form ref="form" :data="formData" :rules="rules">
      <t-form-item label="水质断面检测点成果基本信息表id" name="sectionId">
      <t-input v-model="formData.sectionId" placeholder="请输入水质断面检测点成果基本信息表id"></t-input>
    </t-form-item>
      <t-form-item label="成果详细数据" name="sectionParam">
      <t-input v-model="formData.sectionParam" placeholder="请输入成果详细数据"></t-input>
    </t-form-item>
      <t-form-item label="备注说明" name="remark">
      <t-input v-model="formData.remark" placeholder="请输入备注说明"></t-input>
    </t-form-item>
      <t-form-item label="单位id" name="unitId">
      <t-input v-model="formData.unitId" placeholder="请输入单位id"></t-input>
    </t-form-item>
      <t-form-item label="单位名称（巡查单位）" name="unitName">
      <t-input v-model="formData.unitName" placeholder="请输入单位名称（巡查单位）"></t-input>
    </t-form-item>
      <t-form-item label="创建时间" name="createDate">
      <t-input v-model="formData.createDate" placeholder="请输入创建时间"></t-input>
    </t-form-item>
      <t-form-item label="上传人" name="createId">
      <t-input v-model="formData.createId" placeholder="请输入上传人"></t-input>
    </t-form-item>
      <t-form-item label="更新时间" name="updateDate">
      <t-input v-model="formData.updateDate" placeholder="请输入更新时间"></t-input>
    </t-form-item>
      <t-form-item label="修改人" name="updateId">
      <t-input v-model="formData.updateId" placeholder="请输入修改人"></t-input>
    </t-form-item>
      </t-form>
  </t-dialog>
</template>
<script lang="ts" setup>
import { MessagePlugin } from 'tdesign-vue-next';
import { onMounted, reactive, ref } from 'vue';

import {getList, getInfo, doDelete, doUpdate, doCreate } from '@/api/platform/waterquality/water/section/info/detail';

const props = defineProps({
  visibles: {
    type: Boolean,
    default: false,
  },
});
const INITIAL_DATA = {
        sectionId: '',
        sectionParam: '',
        remark: '',
        unitId: '',
        unitName: '',
        createDate: '',
        createId: '',
        updateDate: '',
        updateId: '',
  };
const form = ref();
const submitLoading = ref(false);
const formData: any = reactive({
  ...INITIAL_DATA,
});
const rules = reactive({
        sectionId: [
      {
        required: true,
        message: '水质断面检测点成果基本信息表id必填',
        type: 'error',
        trigger: 'blur',
      },],
        sectionParam: [
      {
        required: true,
        message: '成果详细数据必填',
        type: 'error',
        trigger: 'blur',
      },],
        remark: [
      {
        required: true,
        message: '备注说明必填',
        type: 'error',
        trigger: 'blur',
      },],
        unitId: [
      {
        required: true,
        message: '单位id必填',
        type: 'error',
        trigger: 'blur',
      },],
        unitName: [
      {
        required: true,
        message: '单位名称（巡查单位）必填',
        type: 'error',
        trigger: 'blur',
      },],
        createDate: [
      {
        required: true,
        message: '创建时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        createId: [
      {
        required: true,
        message: '上传人必填',
        type: 'error',
        trigger: 'blur',
      },],
        updateDate: [
      {
        required: true,
        message: '更新时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        updateId: [
      {
        required: true,
        message: '修改人必填',
        type: 'error',
        trigger: 'blur',
      },],
  });
onMounted(() => {
});
const emit = defineEmits(['update:visibles', 'success']);

const handleOnConfirm = () => {
  form.value.validate().then((validateResult: any) => {
    if (validateResult === true) {
      submitLoading.value = true;
      doCreate({
        ...formData,
      }).then(() => {
        submitLoading.value = false;
        MessagePlugin.success('新增水质断面检测点成果基本信息详情表表成功');
        form.value.clearValidate();
        form.value.reset();
        handleClose();
        emit('success');
      });
    } else {
      MessagePlugin.error('表单验证失败');
    }
  });
};

const handleClose = () => {
  emit('update:visibles', false);
};
</script>
<style lang="less" scoped></style>
